package com.qf.convert;

import org.springframework.core.convert.converter.Converter;
import org.springframework.util.StringUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName StringToDateConvert
 * @Description TODO
 * @Author 86181
 * @Date 2022/9/4 21:58
 * @Version 1.0
 **/
public class StringToDateConvert implements Converter<String, Date> {

    @Override
    public Date convert(String s) {
        if (StringUtils.isEmpty(s)){
            throw new RuntimeException("参数为空");
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date parse=null;
        try {
            parse=simpleDateFormat.parse(s);

        } catch (ParseException e) {
            e.printStackTrace();
        }
        return parse;
    }
}
